package cn.itcast.web.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* 自定义的全局（实现处理异常解析接口）
* */
@Component
public class CustomException implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        /*打印异常到控制台*/
        ex.printStackTrace();
        ModelAndView mv = new ModelAndView("error");
        mv.addObject("errorMsg","系统忙，请联系管理员"+ex.getMessage());
        return mv;
    }
}
